package com.ggh.jinjilive.ui.mine.zhubo;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.BarUtils;
import com.ggh.jinjilive.BaseApplication;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityZhuboStatementBinding;
import com.ggh.jinjilive.mobile.mine.zhubo.ZhuBoStatementMobile;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.gyf.immersionbar.ImmersionBar;

import org.jetbrains.annotations.NotNull;

/**
 * 主播报表
 */

@Route(path = ARouterUtils.ZhuBoStatementActivity)
public class ZhuBoStatementActivity extends BaseActivity<ActivityZhuboStatementBinding> {
    //VM
    private ZhuBoViewModel zhuBoViewModel;
    //跳转到那个
    public int index = 0;
    //
    private String[] mFragmentTitles = {"日报表", "周报表","月激励"};
    private ProfitOrderAdapter profitOrderAdapter;
    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).keyboardEnable(true).init();
        BaseApplication.getInstance().getAppComponent().doInjectionMain(this);
        zhuBoViewModel = new ViewModelProvider(this,viewModelFactory).get(ZhuBoViewModel.class);

    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_zhubo_statement;
    }

    @Override
    public void initParam() {
        super.initParam();
        index = getIntent().getExtras().getInt("index", 0);
    }


    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("主播报表",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
        //适配器
        profitOrderAdapter = new ProfitOrderAdapter(getSupportFragmentManager());
        binding.vp.setAdapter(profitOrderAdapter);
        binding.categoryIndicator.setViewPager(binding.vp, mFragmentTitles);
        binding.vp.setCurrentItem(index);
    }



    @Override
    public void initData() {
        super.initData();
        //主播报表
        zhuBoViewModel.AnchorAuthReport();
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //主播报表
        zhuBoViewModel.mZhuBoStatementMobile.observe(this, new Observer<ZhuBoStatementMobile>() {
            @Override
            public void onChanged(ZhuBoStatementMobile zhuBoStatementMobile) {
                if(null != zhuBoStatementMobile){
                    binding.tvDiamond.setText(zhuBoStatementMobile.getSilver_wallet() + "");
                    if(zhuBoStatementMobile.getIs_signed() == 0){
                        binding.signing.setText("立即签约");
                        binding.signedStatus.setVisibility(View.VISIBLE);
                    }else {
                        binding.signing.setText("签约主播薪表");
                        binding.signedStatus.setVisibility(View.GONE);
                    }
                }
            }
        });
        //立即签约
        binding.signing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:0576-80273133"));
                startActivity(intent);
            }
        });
    }



    class ProfitOrderAdapter extends FragmentPagerAdapter {

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return new ZhuBoStatementFragment(position);
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
//            super.destroyItem(container, position, object);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            super.setPrimaryItem(container, position, object);
        }
    }
}
